<template>
  <div>
    <van-nav-bar :title="`${this.$route.query.key} 的搜索结果`" />

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        v-for="item in list"
        :key="item.art_id"
        :title="item.title"
        @click="$router.push(`/article?id=${item.art_id}`)"
      />
    </van-list>
  </div>
</template>

<script>
import { searchResultAPT } from '@/api/search'
export default {
  data () {
    return {
      loading: false,
      finished: false,
      list: [],
      page: 1
    }
  },
  methods: {
    async onLoad () {

      const res = await searchResultAPT({
        page: this.page,
        q: this.$route.query.key,

      })
      //页面加1
      this.page++

      this.list.push(...res.data.results)
      //结束本地加载状态，可以进行下一次
      this.loading = false

      if (this.list.length >= res.data.total_count) {

        this.finished = true
      }
    }
  }
}
</script>

<style>
</style>